<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

class XmlMods
{

    public $file;

    private $obj;
    private $main_key = 'configuration';

    /**
     * XmlMods::__construct()
     * 
     * @param mixed $file
     * @return
     */
    public function __construct($file)
    {
        $this->file = $file;
        $this->obj = simplexml_load_file($this->file);
    }

    /**
     * XmlMods::getVar()
     * 
     * @param mixed $key
     * @return mixed
     */
    public function getVar($key)
    {
        $main = $this->main_key;
        return $this->obj->$main->children()->$key;
    }

    /**
     * XmlMods::setVar()
     * 
     * @param mixed $key
     * @param mixed $val
     * @return
     */
    public function setVar($key, $val)
    {
        $main = $this->main_key;
        $this->obj->$main->children()->$key = $val;
    }

    /**
     * XmlMods::getAllVars()
     * 
     * @return mixed $return
     */
    public function getAllVars()
    {
        $main = $this->main_key;
        $return = array();
        foreach ($this->obj->$main->children() as $key => $val) {
            $return[$key] = $val;
		}
        return $return;
    }

    /**
     * XmlMods::save()
     * 
     * @return mixed
     */
    public function save()
    {
    	print_r($this->obj);
        return $this->obj->asXML($this->file);
    }
}
?>